﻿@{
    Layout = "_FinanceLayout";
}
<link rel="stylesheet" href="~/layui-v2.5.5/layui/css/modules/laydate/default/laydate.css" media="all">
<script type="text/javascript" src="~/layui-v2.5.5/layui/lay/modules/laydate.js"></script>

<div class="layui-body">
    <!-- 内容主体区域 -->
    <fieldset class="layui-elem-field" style="margin: 20px">
        <legend>部门工资</legend>
        <div class="layui-field-box" style="display:inline-block">
            <form class="layui-form" action="" lay-filter="example" style="width:50%;">
                <div class="layui-container">
                    <div class="layui-row">
                        <div class="layui-col-md4">
                            <div class="layui-form-item">
                                <div class="layui-form-item" style="display:inline-block">
                                    <div class="layui-form-label" style="display:inline-block">请选择部门</div>
                                    <div class="layui-input-block" style="width:150px;">
                                        <select name="dep" lay-filter="aihao2" id="section" style="width:150px;">
                                            <option value="cwc2016001">财务部</option>
                                            <option value="js20160001">教师</option>
                                            <option value="xz20160001">校长</option>
                                            <option value="zjc2016001">政教处</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>


                        <div class="layui-col-md3">
                            <div class="layui-form-item" style="display:inline-block">
                                <label class="layui-form-label">请选择日期</label>
                                @*年选择 *@
                                <input type="text" name="username" lay-verify="title" autocomplete="off" placeholder="请选择年份" class="layui-input" id="picker3" readonly style="width:160px;">
                            </div>
                        </div>

                        <div class="layui-col-md1">
                            <div class="layui-form-item">
                                <button type="button" class="layui-btn" id="view" id="view">查看</button>
                            </div>
                        </div>



                    </div>
                </div>
            </form>
        </div>
        <div style="padding:15px ;margin-top:-40px">
            <table id="demo" lay-filter="test"></table>
        </div>
    </fieldset>
</div>




        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-xs" lay-event="edit" id="edit2">编辑</a>
            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
        </script>

        @section Scripts{
            <script src="~/js/jquery.js"></script>
            <script src="~/layui/layui.js"></script>
            <script>
          layui.use('form', function(){
              var form = layui.form;
              form.render();
          });

        $(function () {
            layui.use('table', function () {
                var table = layui.table;
                $.ajax({
                    url: '/Api/QueryDepartmentWage',
                    data: { 'departmentid': 'cwc2016001' },
                    success: function (data) {  //当请求成功时运行的函数；变量：接受服务器响应结果的值
                        table.render({
                            elem: '#demo'
                            , page: true //开启分页
                            , defaultToolbar: ['filter']
                            , title: 'wage Table'
                            , cols: [[ //表头
                                { field: 'tname', title: '姓名', sort: true, fixed: 'left' }
                                , { field: 'teacherid', title: '工号', sort: true }
                                , { field: 'wagetime', templet: '<div>{{d.wagetime.slice(0,10)}}</div>', title: '日期', sort: true }
                                , { field: 'basicwage', title: '基本工资' }
                                , { field: 'overtimewage', title: '加班工资', sort: true }
                                , { field: 'welfare', title: '福利补贴' }
                                , { field: 'bonus', title: '奖金' }
                                , { field: 'totalwage', title: '总计', sort: true }
                                , { fixed: 'right', title: '操作', toolbar: '#barDemo' }

                            ]]
                            , data: data.wageList
                            , even: true

                        });
                    },
                })

                // 工具栏监听
                table.on('tool(test)', function (obj) {
                    var data = obj.data;
                    if (obj.event === 'del') {
                        layer.confirm('真的删除行么', function (index) {
                            $.ajax({
                                url: "/Api/DeleteTeacherWage",
                                type: "POST",
                                data: { id: data.id },
                                success: function (data) {
                                    if (data.code == 200) {
                                        //删除这一行
                                        obj.del();
                                        //关闭弹框
                                        layer.close(index);
                                        layer.msg("删除成功", { icon: 6 });
                                    } else {
                                        layer.msg("删除失败", { icon: 5 });
                                    }
                                }
                            });
                        });
                    } else if (obj.event === 'edit') {
                        layer.open({
                            type: 2,
                            area: ['380px', '510px'],
                            resize: false,
                            content: '/cwc/EditWage?teacherid=' + data.teacherid + '&time=' + data.wagetime,

                        })
                    }
                });
            });

            var datee;
             layui.use(['layer', 'laydate'], function () {
                var laydate = layui.laydate;
                //时间选择器(年)
                laydate.render({
                    elem: '#picker3',
                    theme: 'molv',
                    type: 'month',
                    btns: ['now'],
                    max: new Date().getMonth(), //getNowFormatDate is not defined
                    ready: function (date) {
                        $("#layui-laydate3").off('click').on('click', '.laydate-month-list li', function () {
                            $("#layui-laydate3").remove();
                        });
                    },
                    change: function (value, dates, edate) {
                        var year = $('#picker3').val(value);
                        datee = value;
                    }
                });
            })
            $("#view").on("click", function () {
                var section = $("#section option:selected").val(); //获取部门
                var wagetime = datee;   //获取日期
                layui.use('table', function () {
                    var table = layui.table;
                    $.ajax({
                        url: '/Api/QueryDepartmentWage',
                        data: {
                            'departmentid': section,
                            'time': wagetime
                        },
                        success: function (data) {  //当请求成功时运行的函数；变量：接受服务器响应结果的值
                            table.render({
                                elem: '#demo'
                                //, toolbar: true
                                , page: true //开启分页
                                , defaultToolbar: ['filter']
                                , title: 'wage Table'
                                , cols: [[ //表头
                                    { field: 'tname', title: '姓名', sort: true, fixed: 'left' }
                                    , { field: 'teacherid', title: '工号', sort: true, fixed: 'left' }
                                    , { field: 'wagetime', templet: '<div>{{d.wagetime.slice(0,10)}}</div>',title: '日期', sort: true, fixed: 'left' }
                                    , { field: 'basicwage', title: '基本工资' }
                                    , { field: 'overtimewage', title: '加班工资', sort: true }
                                    , { field: 'welfare', title: '福利补贴' }
                                    , { field: 'bonus', title: '奖金' }
                                    , { field: 'totalwage', title: '总计', sort: true }
                                    , { fixed: 'right', title: '操作', toolbar: '#barDemo' }

                                ]]
                                , data: data.wageList
                                , even: true
                            });
                        },
                    })


                    // 工具栏监听
                    table.on('tool(test)', function (obj) {
                        var data = obj.data;
                        if (obj.event === 'del') {
                            layer.confirm('真的删除行么', function (index) {
                                $.ajax({
                                    url: "/Api/DeleteTeacherWage",
                                    type: "POST",
                                    data: { id: data.id },
                                    success: function (data) {
                                        if (data.code == 200) {
                                            //删除这一行
                                            obj.del();
                                            //关闭弹框
                                            layer.close(index);
                                            layer.msg("删除成功", { icon: 6 });
                                        } else {
                                            layer.msg("删除失败", { icon: 5 });
                                        }
                                    }
                                });
                            });
                        } else if (obj.event === 'edit') {
                            layer.open({
                                type: 2,
                                area: ['380px', '510px'],
                                resize: false,
                                content: '/cwc/EditWage?teacherid='+data.teacherid+'&time='+data.wagetime,

                            })
                        }
                    });

                });
            })

         })
            </script>
        }

